from functools import wraps
import os
import time
from typing import Callable

from termcolor import colored

if os.path.exists("/opt"):
    AUDIO_ROOT = "/opt/opi_test"
    AUDIO_ROOT = "/opt/opi_test"
else:
    AUDIO_ROOT = "D:/ORANGE/TaskAgent"
    AUDIO_ROOT = "D:/ORANGE/TaskAgent"
ak = "NHYYVR32PAHNBFZRURPX"
sk = "SlbMPJwmUQViEE9BeNK50BsteORqryR32EqjvGyh"
if os.path.exists("/opt"):
    port="/dev/ttyUSB0"
    portWheel = "/dev/ttyUSB1"
else:
    port="COM4"
    portWheel = "COM8"
def timeit(color: str = 'green'):
    def decorator(func: Callable):
        @wraps(func)
        def wrapper(*args, **kwargs):
            start_time = time.time()
            result = func(*args, **kwargs)
            end_time = time.time()
            elapsed_time = end_time - start_time
            print(colored(f"'{func.__module__}.{func.__name__}' 执行时间: {elapsed_time:.4f} 秒", color))
            return result
        return wrapper
    return decorator
